//这是一个临时画布,用于计算表切割位（参数:数据,页面高,可放置的容量
function  distributor( m_table_data,restOffCurrentPageSpace,current_global_position_y) {
    upstairs_cells_height=0;
    dist_total_cells_height=0;//连续不超页的单元格高的累计值 
    
    source_copy_start_position_y=0;//新的表格，新的起点.
    cellsCompareData=[];//列比对数据
    current_columns_index=0;
    current_cell_height=0;
    segmentHeight=0;
    maxTextHeight=0;
    current_tables_canvas_drawing_position_y=0;//这是表格临时画布的起点，作为切割标识。 切后再偏移
    let current_row_has_enough_space_for_cells_text=true; //当单元格预测要被切割后，逐行扫描当前行每个单元格的文字是否在上面的空间是否可以正常容纳。
    let maxCellIndex=0;
    let jump_to_next_row=false;
    b_c_global_position_y=current_global_position_y ;
    dist_copy_start_position_y=current_global_position_y;
    lastCellsTotalOfHeight=0; //处理之前的单元格高度之和
    let collect_cells_height=0;
    //算法:用接近法,获取最大完整切面的位置.
    //切割位置,由表行开始,每一行的开始,就会知道当前行是不是初切割的对象
    //步骤:
    //1.在line遍历过程中判断所在行高度
    //2.在横切单元行上逐个单元格渲染
    //3.在渲染单元格时逐行判断,是否是最后一个完整行,如果是,退出循环
    var tableCanvas = document.createElement('canvas');    
    // 设定canvas元素的宽和高
    tableCanvas.width = 800;
    tableCanvas.height = 9000;	
  
    var myCellCanvas = document.getElementById('cellsCanvas');
    var ctxCellCanvas = myCellCanvas.getContext('2d');
    var ctxTables = tableCanvas.getContext('2d');

    cellStartX = 0;
    cellStartY = 0;
    var alignTypes = ['left', 'center', 'right'];
      var selectCellCounters=0;
   


    // 遍历表格数据，行数据
    // var rows = data.length;
    // var cols = data[0].cells.length;
    let firstCell=true;
    hasToCutCells=false;
    let lastCuttingCellRowIndex=-1;//记录被切割断的表格行索引
    current_columns_index=0;
    //1.在line遍历过程中判断所在行高度
     segmentHeight=restOffCurrentPageSpace;
    //使segmentHeight动态改变，在不够位之后，自动跳转新页面，同时segmentHeight=985
    let current_table_cell_total_height=0;
    let current_table_cell_singleLineHeight=0;

    updateTotalHeight();
    let myTableHeight=tableTotalHeight;
    if(tableTotalHeight<segmentHeight)
      {
        console.log("%c QQ:523 直接收纳这个表格!!!!!!!!!!!!", "color: yellow; background-color: black;");

        segment_Info=[];

        //5-23切割要记录的内容：
                                  //1.形成当前的切块，包括两部分数据，1是拷贝源 的起始与高度；2是目标源的起始坐标与高度；
                                  //2.记录最后一次拷贝源, 目标源 分别的结束位置。将做来下一次分块的起点位置.
                                  //3. 由于两都高度是一样的，只需要一个source_copy_block_height来表示即可。
                                  //4. 保存最后一个单元格高度
                                  //重新定义 这个坐标为全局绝对坐标，包括页面偏移： 
                                  // var source_copy_start_position_y=0;
                                  // var source_copy_block_height=0;
                                  // var dist_copy_start_position_y=0;
                                  // var dist_copy_cell_height=0;
                                  
                                                            

                                  var newSegment1 = {

                                    segment_index: 0,
                                    inMeasure:inMeasure,
                                    debugSn:debugSN,
                                    cells_Dist_Start_Y:dist_copy_start_position_y,
                                    cells_Dist_Height:tableTotalHeight,
                                    cells_Source_Start_Y:0,
                                    sliceType:1,
                                    offset_X: 0,
                                    offset_Y: dist_copy_start_position_y,
                                    width: 700,
                                    height: tableTotalHeight,
                                    pageOffsetY:segmentHeight,
                                    lineText:"",
                                    dataSource:"整表收入，一次性写入"
                                    
                                    };

                                    segmentHeight-=tableTotalHeight //整表改入后 空间减少
                                                           // segment_Info.push(newSegment1);
                            
                                    checkDuplicateAndInsert(segment_Info, newSegment1);

                                // //5-23 当切块发生变化时，更新源与目标源的偏移
                                // source_copy_block_height=cells_Dist_Height;
                                // source_copy_start_position_y+=source_copy_block_height;
                                // dist_copy_start_position_y+=source_copy_block_height;

                                // current_tables_canvas_drawing_position_y+=cells_Source_Height;
                               
                      if(inMeasure==true)
                          return;
      }
    //jsonData.forEach(function(rowData, rowIndex) {
    for (let rowIndex = 0; rowIndex < jsonData.length; rowIndex++) {
      
      let rowData = jsonData[rowIndex];
      scan_Global_RowOfTable=rowIndex;
      let currentLineMaxHeight=rowData.cells[0].height;//当前行的高度
      current_cell_height=rowData.cells[0].height;
      current_row_has_enough_space_for_cells_text=true;

          lastCuttingCellRowIndex=rowIndex;
      single_table_cell_index=rowIndex;
      first_line_text_height=0;//每换一行，清0一次
           //单元格高度大于当前页面可容纳的高度时,认为是被切割的对像,告知自然段渲染时要作相对应的标识.
        if(rowIndex==0)
        {          
              
              
         if(lastCellsTotalOfHeight>segmentHeight)
          {
          hasToCutCells=true;
          console.log("QQ:111:#---#文高大于容量！！");

          }   

          lastCellsTotalOfHeight+=currentLineMaxHeight;//如果不大于指定的区域暂才认为是过了
          
  
      
         }
     

       

        current_columns_index=0;
 

      // rowData.cells.forEach(function(cell, cellIndex) {
      maxCellIndex=rowData.cells.length;//当前表最大列数
   
      let least_segment_Height=0;
      for (let cellIndex = 0; cellIndex < rowData.cells.length; cellIndex++) 
      {
          let cell = rowData.cells[cellIndex];
          var x = cellStartX + cell.x;
          var y = cellStartY + cell.y;   	

          
            firstCell=true;
            if(rowData>0||cellIndex>0)//标识排除当前单元格为首行首列
            firstCell=false;     
           
            current_table_cell_singleLineHeight=cell.height; //获取当前单元格高度

              

            
        if(cell.showBorder==true)
        {
          ctxTables.beginPath(); 
          if(cell.colspan>=1||cell.rowspan>=1)  //处理已合并的单元格。编辑区域扩张
          {
            ctxTables.rect(x, y, cell.mWidth, cell.mHeight);
            textData=cell;
            textData.text=cell.content;       
              
            myCellCanvas = document.getElementById('cellsCanvas');
            //console.log("QQ:1111:",myCellCanvas); // 这应该显示具体的canvas元素信息，而不是null或undefined
            if (myCellCanvas&&textData.text!="") {
            // console.log ("111111111111 textX:"+textX," textY:"+textY, " cellStartX:",cellStartX," cellStartY:",cellStartY);
            myCellCanvas.style.left=x+"px";
            myCellCanvas.style.top =y+"px";
            myCellCanvas.width=cell.mWidth;
            myCellCanvas.height=cell.mHeight;    
            compressStyles();
            
            generateLinesData();
            textData.cursorVisible=false;  
            where_to_call="drawTableCells 05 合并过的单元格";
            current_cell_position_y=current_global_position_y;
            inMeasureAction=1;
            cells_Dist_action=0;
            current_columns_index=cellIndex;
                       //开始渲染在预期内的单元格,采集各个单元格文本切割前的高度与及切害时的位置信息
           //1判断当前单元格是否可能在当前页面能够容纳，如果不可以就要去逐行计算最多可以容纳几行
            if(current_table_cell_singleLineHeight>segmentHeight)
            {

              console.log("QQ:523: 在合并单元格情况下：：当前单元格无法在当前页面完全绘制完，，表格首行预测能否放下，如不能表头就移到下一页:");

              //renderText();		
              //page_segment:页面剩余容量
              //cell_width:  单元格宽度
              //cell_height: 单元格高度，逐行输出时判断边界高度
              //dist_pages_position_start_x: 目标页面起始位置x
              //dist_pages_position_start_y: 目标页面起始位置y
              //sour_canvas_position_start_x: 源画布起始位置x
              //sour_canvas_position_start_y: 源画布起始位置y       

              let dist_pages_position_start_y=current_global_position_y;
              let dist_pages_position_start_x=0;
              let sour_canvas_position_start_x=0;
              let sour_canvas_position_start_y=source_copy_start_position_y;
              dist_copy_start_position_y=current_global_position_y;//目标页面的起点重新定位
              
             measureSegment(
              true,   
              segmentHeight,            
              cell.width,
              cell.height,
              dist_pages_position_start_x,
              dist_pages_position_start_y,
              sour_canvas_position_start_x,
              sour_canvas_position_start_y

            );

              inMeasureAction=0;
              if(cells_Dist_action==1)//上一页空间不够用
              {  //上一页空间不够,这里补回去
                              
                                current_cell_position_y=(currentPage)*985+(cell.mHeight-cells_Source_Height); 
                                upstairs_cells_height+=cell.mHeight ;//计算一下上楼单元格占用的高度
                                collect_cells_height+=cell.mHeight;//换页后重新计算有效，有可能不正确 待验证
                                console.log("QQ:523: 合并单元格切割页标记2 current_cell_position_y:",current_cell_position_y ," sn:",debugSN," rowIndex:",rowIndex, " cellIndex:",cellIndex," cells_Dist_Start_Y:",cells_Dist_Start_Y," cells_Source_Height:",cells_Source_Height," cells_Dist_action:",cells_Dist_action);
                            
              }
            
              if(hasNoEnoughSpacing==true||cells_Dist_action==1) //首行不够空间
              {
                currentPage++;
                hasNoEnoughSpacing=false;
                segmentHeight=985;
                console.log("QQ:523:### 单元格首行跳出"," rowIndex:",rowIndex, " cellIndex:",cellIndex);
                if(inMeasure==true)
                break;
              }

            }

            //console.log("QQ:1111:### 合并过的单元格"," upstairs:",upstairs_cells_height);
            }
          }
          else //if(当前单元可被合并过)
          {
             
                //以下处理非合并单元格的数据
                ctxTables.rect(x, y, cell.width, cell.height);      
                textData=cell;
                textData.text=cell.content;   
                myCellCanvas = document.getElementById('cellsCanvas');
                //console.log(myCellCanvas); // 这应该显示具体的canvas元素信息，而不是null或undefined
                if (myCellCanvas&&textData.text!="") {
      
                myCellCanvas.style.left=x+"px";
                myCellCanvas.style.top =y+"px";
                myCellCanvas.width=cell.width;
                myCellCanvas.height=cell.height;    
                                  
                   
                     //var single_table_cell_index=0; 
                     single_table_cell_index=cellIndex; //在绘制表格过程判断当前行有可能出现跨页的情况，需要记录当前行的单元格的索引,标识当前哪一列正在绘制
                                                        //当整行绘制完成后，会将这几列的真实高度作为参考比较.哪列触发了切口文字完整性计算
                     //上一楼的单元格总高 upstairs_cells_height
                     //**** 非合并单元格的数据 当前行是否放行下 */
                             //当前绘制的单元格已经超过了当前页的高度容量,要去计算当前单元格内容的真实高度
                     if(current_table_cell_singleLineHeight>segmentHeight)//开始渲染在预期内的单元格,采集各个单元格文本切割前的高度与及切害时的位置信息
                      {

                        

                                               //在情形1 这种情况下，首先要通过renderText()计算单元格上的文字是否正常显示而不被切割成两半。从第一列到最后一列做标识，如果完成OK，就按segmentHeight划分单元格
                       //假设有个变量current_row_has_enough_space_for_cells_text=true,在每行扫描时复位，而maxCellIndex为当前表格的最大列数，
                       //在cellIndex==maxCellIndex判断current_row_has_enough_space_for_cells_text是否为true ,如果是 就输出切割信息。
                       //为了统计当前页多个有效单元格内容的累计值假设变量为let collect_cells_height=0;

                       //情形1 说明：当单元格文字部分可以完整显示在上半部，此时用segmentHeight作为 当前current_cell_position_y的增量
                       console.log("QQ:523  在非合并单元格情况：：判断当前行有可能出现跨页的情况 current_global_position_y+total_cells_height：",current_global_position_y+dist_total_cells_height," dist_total_cells_height:" ,dist_total_cells_height," rowIndex:",rowIndex, " cellIndex:",cellIndex, "myTableHeight:",myTableHeight,"sn:",debugSN," 行高: " ,current_table_cell_singleLineHeight," segmentHeight:",segmentHeight," index:",cellIndex," upstairs_cells_height:",upstairs_cells_height);
                        compressStyles();                  
                        generateLinesData();
                        textData.cursorVisible=false;   
                        where_to_call="drawTableCells 06判断当前行有可能出现跨页的情况";
                        current_cell_position_y=current_global_position_y+dist_total_cells_height;
                        inMeasureAction=1;
                        cells_Dist_action=0;
                        current_columns_index=cellIndex;
              //renderText();		
              //page_segment:页面剩余容量
              //cell_width:  单元格宽度
              //cell_height: 单元格高度，逐行输出时判断边界高度
              //dist_pages_position_start_x: 目标页面起始位置x
              //dist_pages_position_start_y: 目标页面起始位置y
              //sour_canvas_position_start_x: 源画布起始位置x
              //sour_canvas_position_start_y: 源画布起始位置y       

              let dist_pages_position_start_y=current_cell_position_y;
              let dist_pages_position_start_x=0;y
              let sour_canvas_position_start_x=0;
              let sour_canvas_position_start_y=source_copy_start_position_y;
              dist_copy_start_position_y=current_cell_position_y;//目标页面的起点重新定位
              dist_pages_position_start_y=dist_copy_start_position_y;

              console.log("QQ:523: 当前单元格无法在当前页面完全绘制完，，非合并单元格预测能否放下，如不能表头就移到下一页:");
             //将单元格送进去加工，返回位置 
             //segmentHeight
             measureSegment(
              true, 
              segmentHeight,               
              cell.width,
              cell.height,
              dist_pages_position_start_x,
              dist_pages_position_start_y,
              sour_canvas_position_start_x,
              sour_canvas_position_start_y);
                        inMeasureAction=0;
                          if(cells_Dist_action==1)//上一页空间不够用
                          {  //上一页空间不够,这里补回去
                             
                              dist_total_cells_height=0
                              segmentHeight=985;
                              
                               if((myTableHeight-Hs)<segmentHeight)
                                {
                                  console.log("QQ:518: 第二页放得下!!!!!切割页标记----- segmentHeight:",segmentHeight,"currentPageY:",current_cell_position_y%985," cell.Height:",cell.height,"current_cell_position_y:",current_cell_position_y ," sn:",debugSN," rowIndex:",rowIndex, " cellIndex:",cellIndex," cells_Dist_Start_Y:",cells_Dist_Start_Y," cells_Source_Height:",cells_Source_Height," cells_Dist_action:",cells_Dist_action);
                                      
                                }
                              //currentPage++;
                                  if((cell.height-Hs)<segmentHeight)
                                  {
                                      //进入下一页：要重新记录当页面的已绘制单元格的高度
                                      current_cell_position_y=(currentPage)*985+(cell.height-cells_Source_Height); 
                                          upstairs_cells_height+=cell.height ;//计算一下上楼单元格占用的高度 

                                      collect_cells_height+=(cell.height-cells_Source_Height);//累计源Table自向而下已绘制到的位置
                                      dist_total_cells_height=collect_cells_height;//非跨页单元格高之和
                                      segmentHeight=segmentHeight-(cell.height-cells_Source_Height); //当前面使用后剩下这部分空间
                                      let currentPages=Math.floor(current_cell_position_y/985);
                                      let me=Math.floor(current_cell_position_y%985)>0?1:0;
                                      currentPages+=me;
                                

                                      //页面与表格单元格绘制规则模型
                                      //***************************************************/
                                      // var Hp=985; //页面高度
                                      // var Hct=0;  //下半页单元格累计高度  Hct<=Hp
                                      // var Hc=0 ;  //当前单元格高度
                                      // var Hs=0 ;  //上半截单元格高度（当一页容不下一行单元格时）
                                      // var Ha=0 ;  //Ha=Hc-Hs
                                      // var Has=0;  //下半截页面可用高度 Hp-Hct
                                      //***************************************************/
                                      Has=segmentHeight;//剩下的下半截页面可用高度
                                      //Hct=current_cell_position_y;
                                             console.log("QQ:523: 第二页放得下切割页标记 绘制首行后剩下空间 segmentHeight:",segmentHeight,"current_cell_position_y%985:",
                                      current_cell_position_y%985,"current_cell_position_y:",current_cell_position_y ," cell.Height:",cell.height,
                                      " currentPage:",currentPages,
                                      "\r\n sn:",debugSN," rowIndex:",rowIndex, " cellIndex:",cellIndex," cells_Dist_Start_Y:",cells_Dist_Start_Y,
                                      " cells_Source_Height:",cells_Source_Height," cells_Dist_action:",cells_Dist_action);
                                      
                                       console.log(`%c QQ:523: 上半截结束，下半截开始->>下半页单元格累计高度  Hct<=Hp:${Hct} 上半截单元格高度Hs:${Hs},  下半截页面可用高度Has:${Has}, 当前单元格高度Hc:${Hc}`,"color:red");
                                       if(inMeasure==true)
                                      break;//同列不再统计
                                  }
                                  else
                                  {
                                      current_row_has_enough_space_for_cells_text=false;
                                      console.log("QQ:523: 第二页放不下切割页标记segmentHeight:",segmentHeight,"currentPageY:",current_cell_position_y%985," 下半部的cell.Height:",cell.height-(cell.height-cells_Source_Height),"current_cell_position_y:",current_cell_position_y ," sn:",debugSN," rowIndex:",rowIndex, " cellIndex:",cellIndex," cells_Dist_Start_Y:",cells_Dist_Start_Y," cells_Source_Height:",cells_Source_Height," cells_Dist_action:",cells_Dist_action);
                                     

                                  }
                                
                          } //不够容纳
                          else//if (单元格不够空间容纳文字 切分两部分)
                          {
                            
                            //文字够空间容纳,但无法容完所有表格线框
                           if((maxCellIndex-1)==cellIndex)
                            {
                              if(current_row_has_enough_space_for_cells_text==true)
                                {
                                  least_segment_Height=segmentHeight;
                                  let least_cell_Source_Height=cells_Source_Height;//原来单元格高度
                                  collect_cells_height+=segmentHeight ;//之前的单元格再加容纳//(cell.height-cells_Source_Height)+segmentHeight;
                                  segmentHeight=0;//耗尽所有空间 segmentHeight-(cell.height-cells_Source_Height);
                                  console.log("QQ:523  单元格被切，上半部是segmentHeight全部，而后半部分 等于剩余单元格容量,此时要作标记!===============");
                                  console.log("QQ:523: 111第二页放不下切割页标记segmentHeight:",segmentHeight,"currentPageY:",current_cell_position_y%985," current_cell_position_y:",current_cell_position_y,
                                  " cell.Height:",cell.height,"current_cell_position_y:",current_cell_position_y ," sn:",debugSN," rowIndex:",rowIndex, 
                                  " cellIndex:",cellIndex," cells_Dist_Start_Y:",cells_Dist_Start_Y," cells_Source_Height:",cells_Source_Height,
                                  " cells_Dist_action:",cells_Dist_action);
                                 
                                  dist_total_cells_height=collect_cells_height;//非跨页单元格高之和
                                     
                                  console.log("QQ:523: ######1 内部累加"," rowIndex:",rowIndex, " cellIndex:",cellIndex,"减去上半部分: dist_total_cells_height:",dist_total_cells_height," cells_Source_Height:",cells_Source_Height," least_segment_Height:",least_segment_Height);
                                  
                                   //跳到下一页，计算出他的全局Y
                                   let  currentPageNo=Math.floor(dist_copy_start_position_y/985);
                                   //currentPageNo++;//source_copy_block_height
                                   let  myRestSpace=dist_copy_start_position_y%985;
                                   if(myRestSpace>0 )
                                    currentPageNo++;

                                   //1.计算出下一页的的偏移量
                                   dist_copy_start_position_y=currentPageNo*985;
                                   //2.计算出高度 dist_copy_cell_height
                                  
                                   cells_Source_Height=dist_copy_cell_height-cells_Source_Height;
                                   //这里只是次页的开始，不能直接写图像。测试中
                                   //dist_total_cells_height
                                   console.log("QQ:523 源图起始位置Y:",source_copy_start_position_y+source_copy_block_height," 目标起始位置:",dist_copy_start_position_y,"->pageY:",dist_copy_start_position_y%985," 剩余容量:",segmentHeight," 单元格组高:",dist_total_cells_height );
                                
                                   
                                  var newSegment2 = {
                                      segment_index: 0,
                                      inMeasure:true,
                                      debugSn:"Tab001",
                                      cells_Dist_Start_Y:dist_copy_start_position_y,
                                      cells_Dist_Height:dist_total_cells_height,
                                      cells_Source_Start_Y:source_copy_start_position_y,
                                      sliceType:1,
                                      offset_X: 0,
                                      offset_Y: lastSegmentPosition,
                                      width: 700,
                                      height: dist_total_cells_height,
                                      pageOffsetY:segmentHeight,
                                      lineText:"",
                                      dataSource:"切割开文字够空间容纳2-------------剩余单元格处理"
                                     
                                      };
                                    
                                   checkDuplicateAndInsert(segment_Info, newSegment2);

                                   current_global_position_y=dist_copy_start_position_y;
                                   source_copy_start_position_y=source_copy_start_position_y+source_copy_block_height;//下一个源图起始位置。

                                   console.log("$$$QQ:523 单元格高：",dist_copy_cell_height,"  最后页面容量:",least_segment_Height," 剩下的单元格高度：",dist_copy_cell_height-least_segment_Height);
                                   if((dist_copy_cell_height-least_segment_Height)>0)
                                    {
                                      console.log("$$$QQ:523 上一页的单元格，要掉下去：",dist_copy_cell_height-least_segment_Height);

                                      //这里还要个工作要作：如果当前单元格超过985，也有可能要写分段数据组TODO:2024-5-23 
                                      cells_Source_Height=collect_cells_height;//换页后高度重新计算
                                
                                       current_cell_position_y=(currentPage+1)*985+1; 


                                       current_tables_canvas_drawing_position_y+=cells_Source_Height;
                                       collect_cells_height=(cell.height-cells_Source_Height);//换页后重新计算

                                    var newSegment2 = {
                                      segment_index: 0,
                                      inMeasure:inMeasure,
                                      debugSn:debugSN,
                                      cells_Dist_Start_Y:current_cell_position_y,
                                      cells_Dist_Height:dist_copy_cell_height-least_segment_Height,
                                      cells_Source_Start_Y:current_tables_canvas_drawing_position_y,
                                      sliceType:1,
                                      offset_X: 0,
                                      offset_Y: lastSegmentPosition,
                                      width: 700,
                                      height: dist_copy_cell_height-least_segment_Height,
                                      pageOffsetY:segmentHeight,
                                      lineText:"",
                                      dataSource:"剩余单元格处理"
                                     
                                      };
                                   
      
                                      checkDuplicateAndInsert(segment_Info, newSegment2);
                                    }
                                  
                                    jump_to_next_row=true;
                                    if(inMeasure==true)
                                    break;

                                }

                            }

                          }



                    
                
                      }     
                      else{
                          current_cell_position_y+=current_table_cell_singleLineHeight;//不超过可用容量，直接拿下
                          upstairs_cells_height+=cell.height ;//计算一下上楼单元格占用的高度
                          collect_cells_height+=cell.height;
                          dist_total_cells_height=collect_cells_height;//非跨页单元格高之和

                          console.log("QQ:523: ######2 内部累加"," rowIndex:",rowIndex, " cellIndex:",cellIndex," dist_total_cells_height:",dist_total_cells_height);
                          segmentHeight=segmentHeight-cell.height;
                          console.log("QQ:523  还正常放得下单元格 rowIndex:",rowIndex, " cellIndex:",cellIndex," sn:",debugSN," 累计行高：",dist_total_cells_height," 当前单元格行高: " ,cell.height," 绘制本行后剩余空间 segmentHeight:",segmentHeight," currentPageStartY:"," upstairs_cells_height:",upstairs_cells_height," currentPositionY:",current_cell_position_y%985," current__position_y:",current_cell_position_y, " current_pages:",current_cell_position_y/985);
                          
                          //页面与表格单元格绘制规则模型
                          //***************************************************/
                          // var Hp=985; //页面高度
                          // var Hct=0;  //下半页单元格累计高度  Hct<=Hp
                          // var Hc=0 ;  //当前单元格高度
                          // var Hs=0 ;  //上半截单元格高度（当一页容不下一行单元格时）
                          // var Ha=0 ;  //Ha=Hc-Hs
                          // var Has=0;  //下半截页面可用高度 Hp-Hct
                          //***************************************************/
                          Has=segmentHeight;//剩下的下半截页面可用高度
                          Hc=cell.height;   //因为空间够用，要在这里赋值单元格高度
                          Hct+=Hc;          //直接放得下就累加
                          console.log(`%c QQ:523: 上半截结束，下半截单元格累加中->>下半页单元格累计高度  Hct<=Hp:${Hct} pageGlobalYPosition:${pageGlobalYPosition} 上半截单元格高度Hs:${Hs},  下半截页面可用高度Has:${Has}, 当前单元格高度Hc:${Hc}`,"color:red");
                                                    
                          if(inMeasure==true)
                          break;//同列不再统计,反正不够空间了
                           //文字够空间容纳
                           
                         
                      }        
              }
            
          }
         
          
          ctxTables.fillStyle = selectCellCounters>=2&&cell.selected ? 'lightblue' : 'white';
            // 设置字体样式
                  ctxTables.font = '16px Microsoft YaHei'; 
          //ctx.fill();//透明背景
          if (cell.showBorder) {
            ctxTables.lineWidth = cell.borderSize;
            ctxTables.textBaseline = 'middle';             
            ctxTables.strokeStyle = 'black';
            ctxTables.stroke();
          }
           if((editor_locked_cellRecord.columns!=cellIndex||editor_locked_cellRecord.rows!=rowIndex)||isInScrolling===true)//当前非编辑时
          {        

           // 将第一个画布的内容复制到第二个画布
           if(myCellCanvas&&myCellCanvas.width>0&&myCellCanvas.height>0)
           ctxTables.drawImage(myCellCanvas, x, y); // 复制到第二个画布的上
           
          }
          else
          {
              lastSizeOfCellCanvas.left=(x+canvasOffset.left)+"px";
              lastSizeOfCellCanvas.top=(y+canvasOffset.top)+"px";
              lastSizeOfCellCanvas.width=cell.width;    
                              lastSizeOfCellCanvas.height= cell.height;

          }

          ctxTables.strokeStyle = 'black';
          ctxTables.textBaseline = 'middle';
          ctxTables.textAlign = 'left';
        }          
        
          // if(hasNoEnoughSpacing==true||cells_Dist_action==1) //首行不够空间
          // {
          // 				currentPage++;
          //   hasNoEnoughSpacing=false;
          //   segmentHeight=985;
          //   console.log("QQ:1111:444### 单元格首行跳出"," rowIndex:",rowIndex, " cellIndex:",cellIndex);
          //   break;
          // }
          current_columns_index++;
          if(jump_to_next_row)
            {
              jump_to_next_row=false;
              break;
            }
           
      };
      //按行累计表每行的高,current_table_cell_singleLineHeight已在第0列时获得当前行高的值. 
      
      //console.log("QQ:1111  current_table_cell_total_height: " ,current_table_cell_total_height," upstairs_cells_height:",upstairs_cells_height," segmentHeight:",segmentHeight," current_table_cell_singleLineHeight:",current_table_cell_singleLineHeight," lastSegmentPosition:",lastSegmentPosition," rowIndex:",rowIndex);
      upstairs_cells_height+=current_table_cell_singleLineHeight;
      current_table_cell_total_height+=current_table_cell_singleLineHeight;

     
       

         



        
    };

   
    // if(current_table_cell_total_height>segmentHeight)//单元格大于了表格,就要翻页. 此时当前页的文本行高度不一定是整个segmentHeight的高度。可能是小于它的,所以要从上面绘制的单元格组中获取
    // {
    //   console.log("QQ:523 完成切割屏后显示切片信息:",segment_Info.length);
    //     for (var i = 0; i < segment_Info.length; i++) 
    //     {
    //     var segment = segment_Info[i];
    //     lastSegmentPosition=segment.height;
    //     let page=Math.floor(segment.cells_Dist_Start_Y/Hp);
    //     let restPage=segment.cells_Dist_Start_Y%Hp;
    //     if(restPage>0)
    //       page+=1;
    //     console.log("QQ:523 切口 " + (i + 1) + "： inPage:",page,"segment_index: " + segment.segment_index," Source_Start_Y:",segment.cells_Source_Start_Y,"Dist_Start_Y:",segment.cells_Dist_Start_Y,"Dist_Start_Y%985:",segment.cells_Dist_Start_Y%985," width: " + segment.width,"  height: " + segment.height);
    //    }

    // }
          // 将canvas内容转换为data URL
    var dataURL = tableCanvas.toDataURL('image/png');

    // 创建一个下载链接
    var downloadLink = document.createElement('a');
    downloadLink.href = dataURL;
    downloadLink.download = 'canvas-image.png';

    // 触发下载
    // 使用JavaScript创建一个点击事件
    // 这个事件不需要用户实际点击链接
    downloadLink.dispatchEvent(new MouseEvent('click', {
      'bubbles': true,
      'cancelable': true,
      'view': window
    }));

    //console.log("QQ8::finishDrawTable---------222----------------------------------------");
       myCellCanvas = document.getElementById('cellsCanvas');
      if(lastTextData!=null)
      {
        textData=lastTextData;
        //console.log("Q9 loadAtFirstTime:", loadAtFirstTime);
        if(loadAtFirstTime)
        {
          //console.log ("Q99999999999999999 第一次隐藏888");
          myCellCanvas.style.display = 'none';
          return;

        }

        if (myCellCanvas&&textData.text!=""&&isInScrolling==false) {
          //console.log ("Q8888888888888888888 text:"+textData.content," lastSizeOfCellCanvas.left:"+lastSizeOfCellCanvas.left, " lastSizeOfCellCanvas.top:",lastSizeOfCellCanvas.top," cellStartY:",cellStartY);
          // myCellCanvas.style.left=1500+"px";                       
          // myCellCanvas.style.top =200+"px";
          myCellCanvas.style.display = 'block';
          myCellCanvas.style.left=lastSizeOfCellCanvas.left;                       
          myCellCanvas.style.top =lastSizeOfCellCanvas.top;
          myCellCanvas.width=lastSizeOfCellCanvas.width;
          myCellCanvas.height=lastSizeOfCellCanvas.height;    
          myCellCanvas.style.zIndex=9999;
          compressStyles();
          generateLinesData();
          textData.cursorVisible=false;
          where_to_call="drawTableCells 07判断当前行有可能出现跨页的情况";
          renderText();		
          finishDrawTable=true;
          //console.log("QQ:111::finishDrawTable---------33333----------------------------------------");
          }
        }
        else
        { finishDrawTable=true;
          //console.log("QQ8::finishDrawTable---------4444----------------------------------------");
         // console.log ("Q98888888888888888888 我没点点点");
          if(loadAtFirstTime)
          {
            //console.log ("Q99999999999999999 第一次隐藏");
            myCellCanvas.style.display = 'none';
            return;

          }
        }
        isInScrolling=false;
       
        //console.log("QQ8::finishDrawTable-----------------55555--------------------------------");
  }